package com.innovations.inn.service.impl;

import com.innovations.common.utils.ExtHelper;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import com.innovations.inn.domain.AdministrativeDivision;
import com.innovations.inn.mapper.AdministrativeDivisionMapper;
import com.innovations.inn.service.IAdministrativeDivisionService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 行政区划Service业务层处理
 *
 * @author dp
 * @date 2024-01-16
 */
@Service
public class AdministrativeDivisionServiceImpl implements IAdministrativeDivisionService {
    @Autowired
    private AdministrativeDivisionMapper administrativeDivisionMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询行政区划
     *
     * @param divisionId 行政区划主键
     * @return 行政区划
     */
    @Override
    public AdministrativeDivision selectAdministrativeDivisionByDivisionId(Long divisionId) {
        return administrativeDivisionMapper.selectAdministrativeDivisionByDivisionId(divisionId);
    }

    /**
     * 查询行政区划列表
     *
     * @param administrativeDivision 行政区划
     * @return 行政区划
     */
    @Override
    public List<AdministrativeDivision> selectAdministrativeDivisionList(AdministrativeDivision administrativeDivision) {
        return administrativeDivisionMapper.selectAdministrativeDivisionList(administrativeDivision);
    }

    /**
     * 新增行政区划
     *
     * @param administrativeDivision 行政区划
     * @return 结果
     */
    @Override
    public int insertAdministrativeDivision(AdministrativeDivision administrativeDivision) {
        return administrativeDivisionMapper.insertAdministrativeDivision(administrativeDivision);
    }

    /**
     * 修改行政区划
     *
     * @param administrativeDivision 行政区划
     * @return 结果
     */
    @Override
    public int updateAdministrativeDivision(AdministrativeDivision administrativeDivision) {
        return administrativeDivisionMapper.updateAdministrativeDivision(administrativeDivision);
    }

    /**
     * 批量删除行政区划
     *
     * @param divisionIds 需要删除的行政区划主键
     * @return 结果
     */
    @Override
    public int deleteAdministrativeDivisionByDivisionIds(Long[] divisionIds) {
        return administrativeDivisionMapper.deleteAdministrativeDivisionByDivisionIds(divisionIds);
    }

    /**
     * 删除行政区划信息
     *
     * @param divisionId 行政区划主键
     * @return 结果
     */
    @Override
    public int deleteAdministrativeDivisionByDivisionId(Long divisionId) {
        return administrativeDivisionMapper.deleteAdministrativeDivisionByDivisionId(divisionId);
    }

    /**
     * 实体数据补全
     *
     * @param administrativeDivision 实体
     * @param userId                 用户id
     * @param crateType              创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(AdministrativeDivision administrativeDivision, Long userId, Integer crateType) {
        //主键
        if (administrativeDivision.getDivisionId() == null || administrativeDivision.getDivisionId().isEmpty()) {
            administrativeDivision.setDivisionId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
    }

}
